package com.tjakus.bean;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.faces.event.ValueChangeEvent;
import com.tjakus.hibernate.HibernateUtil;
import com.tjakus.hibernate.Statistics;
import com.tjakus.hibernate.Users;
import com.tjakus.logging.Logging;

public class StatisticsBean {

	private List<Statistics> statisticsListPerUser;
	private String selectedEmail;
	private List<String> emailList = this.init();
	
	
	public List<String> init() {
		Logging.getLogger().info("INITIALIZATION!!!");
		List<String> emailList2 = new ArrayList<>();
		List<Users> usersList = HibernateUtil.getAllUsers();
		for (Iterator<Users> iter = usersList.iterator(); iter
				.hasNext();) {
			emailList2.add(iter.next().getEmail());
		}
		return emailList2;
	}
	
	public List<Statistics> getStatisticsListPerUser() {
		return statisticsListPerUser;
	}

	public void setStatisticsListPerUser(List<Statistics> statisticsListPerUser) {
		this.statisticsListPerUser = statisticsListPerUser;
	}

	public String getSelectedEmail() {
		return selectedEmail;
	}

	public void setSelectedEmail(String selectedEmail) {
		this.selectedEmail = selectedEmail;
	}

	public List<String> getEmailList() {
		return emailList;
	}

	public void setEmailList(List<String> emailList) {
		this.emailList = emailList;
	}

	public void emailChange(ValueChangeEvent event) {
		Logging.getLogger().info("DISPLAY SERVICES: " + event.getNewValue().toString());
		selectedEmail = (String) event.getNewValue();
		statisticsListPerUser = HibernateUtil.getStatisticsByEmail(selectedEmail);
	}


	
}
